<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Product_detail extends Public_Controller {

    protected $_product;

    public function __construct() {
        parent::__construct();
        $this->_load();
    }

    public function index($iId = 0) {
        $this->get($iId);
        $this->_replacePhrase();
    }

    private function _load() {
        $this->load->helper(array('url', 'form'));
        $this->load->model(array('user', 'product'));
        $this->_product = $this->get();
    }

    private function _replacePhrase() {
        $this->lang->load('public/general', $this->_slang_name);
        $this->lang->load('public/product_detail', $this->_slang_name);
        $this->_adata['sloginFail'] = $this->_serror;
        $this->_adata['product'] = $this->_product;
        $this->fill_phrase('product_detail', $this->_adata, $this->lang->language);
    }
    
    public function get($iId = null){
        if(empty($iId)){
            return false;
        }
        
        $this->_product = $this->product->getById($iId);
        return;
    }
    
    public function save(){
        if(!$this->input->is_ajax_request()){
            return false;
        }
        
        if(!(bool)$iId = $this->input->post('id')){
            return $this->return_fail_json(array('id' => $iId), 'Save unsuccessfully');
        };
        
        if((bool)$this->product->save($iId, $this->_ouser->id)){
            return $this->return_success_json(array('id' => $iId), 'Save successfully');
        }
        
        return $this->return_fail_json(array('id' => $iId), 'Save unsuccessfully');
    }
}
?>
 